package platform.persistence.config;

import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import java.net.UnknownHostException;

@Configuration
@PropertySource("classpath:mongoconf.properties")
public class MongoConfigContext {

    @Value("${mongo-host}")
    private String host;

    @Value("${mongo-port}")
    private int  port;

    @Value("${mongo-dbname}")
    private String dbName;

    @Bean
    public MongoDbFactory mongoDbFactory () throws UnknownHostException {
        return new SimpleMongoDbFactory(new MongoClient(host,port),dbName);
    }

    @Bean
    public StandardMongoTemplate mongoTemplate()throws UnknownHostException{
        return new StandardMongoTemplate(mongoDbFactory());
    }


}
